<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>课程修改</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">

<link rel="stylesheet" href="./css/x-admin.css" media="all">

</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>课程管理</cite></a>
			<a><cite>课程信息</cite></a> <a><cite>课程信息修改</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<form class="layui-form layui-form-pane">
						<div id="msg" style="color: red; margin-bottom: 15px;"><%=request.getAttribute("msg") == null ? "" : request.getAttribute("msg")%></div>
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程号
							</label>
							<div class="layui-input-block">
								<input type="text" name="courseNo" id="courseNo"
									value="<%=request.getParameter("courseNo")%>"
									autocomplete="off" placeholder="请输入文字" class="layui-input"
									lay-verify="" readonly="readonly">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程类别
							</label>
							<div class="layui-input-block">
								<input type="text" name="subJect" id="subJect"
									value="<%=request.getParameter("subJect")%>" autocomplete="off"
									placeholder="请输入文字" class="layui-input" lay-verify="">
							</div>
						</div>
						
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程名称
							</label>
							<div class="layui-input-block">
								<input type="text" name="courseName" id="courseName"
									value="<%=request.getParameter("courseName")%>"
									autocomplete="off" placeholder="5个左右,8汉字以内,用英文,隔开"
									class="layui-input" lay-verify="" readonly="readonly">
							</div>
						</div>

						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程描述
							</label>
							<div class="layui-input-block">
								<textarea placeholder="请输入内容" class="layui-textarea"
									name="courseDesc" id="courseDesc"><%=request.getParameter("courseDesc")%></textarea>
							</div>
						</div>

						<div class="layui-form-item">
							<div class="layui-form-item " id="">
								<label for="link" class="layui-form-label"> <span
									class="x-red">*</span>课程图片
								</label> <img src="<%=request.getParameter("coursePic")%>" id="pimages"
									name="pimages" style="width: 400px; height: 200px;" /> <input
									name="coursePic" id="coursePic" type="hidden"
									value="<%=request.getParameter("coursePic")%>">
							</div>

							<div class="layui-input-inline">
								<div class="site-demo-upbar">
									<div class=" layui-upload-button" style="border: #FFFFFF;">
										<button type="button" class="layui-btn" id="test1">
											<i class="layui-icon">&#xe67c;</i>修改图片
										</button>
										<input class="layui-upload" type="file" accept="undefined"
											id="previewImg" name="images" onchange="upload()">
									</div>
								</div>
							</div>
						</div>

						<div class="layui-form-item">
							<button class="layui-btn" type="submit" lay-submit=""
								lay-filter="upd">保存</button>
						</div>
					</form>
					<div style="height: 100px;"></div>
				</div>
			</div>
		</div>
	</div>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script src="./js/x-layui.js" charset="utf-8"></script>

	<script>
		layui.use([ 'element', 'layer', 'form' ], function() {
			$ = layui.jquery;//jquery
			lement = layui.element();//面包导航
			layer = layui.layer;//弹出层
			form = layui.form()

			//监听提交
			form.on('submit(upd)', function(data) {
				var courseNo = $("input[name='courseNo']").val();
				var subJect = $("input[name='subJect']").val();
				var courseName = $("input[name='courseName']").val();
				var courseDesc = $("#courseDesc").val();
				var coursePic = $("input[name='coursePic']").val();

				if (subJect == "") {
					layer.msg('课程类型不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseDesc == "") {
					layer.msg('课程描述不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (coursePic == "") {
					layer.msg('图片必须上传', {
						icon : 5,
						time : 2000
					});
					return false;
				}

				//修改
				$.ajax({
					type : "get",
					url : "CourseServlet",
					data : {
						courseNo : courseNo,
						subJect : subJect,
						courseName : courseName,
						courseDesc : courseDesc,
						coursePic : coursePic,
						op : "upd"
					},
					success : function(data) {//提交成功后的回调函数
						if (data.code == 0) {
							layer.msg(data.msg, {
								icon : 5,
								time : 2000
							});
							return false;
						} else {
							layer.msg(data.msg, {
								icon : 6,
								time : 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer
										.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;
						}
					},
					dataType : "json"//预期返回的数据类型
				});
				return false;//!!!!重要，否则会同时提交给AddCourse.jsp！！！
			});

		})
	</script>

	<!--缩略图上传-->
	<script>
		function upload() {
			var formData = new FormData();
			formData.append('images', $('#previewImg')[0].files[0]);
			layer.msg('图片修改中', {
				icon : 16
			});
			$.ajax({
				type : "post",
				processData : false,
				contentType : false,
				url : "FileUploadServlet",
				data : formData,
				dataType : "json",//预期返回的数据类型
				success : function(data) {
					if (data.code == 1) {
						//关闭提示信息
						layer.closeAll('loading');
						//data.msg 图片路径
						$("#pimages").attr('src', data.msg);
						$("#coursePic").val(data.msg);
						return false;
					} else {
						layer.msg(data.msg, {
							icon : 2,
							time : 3000
						});
					}
				}
			});
		}
	</script>
</body>
</html>